/*
 * Copyright (c) 2017-2019 THL A29 Limited, a Tencent company. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <tencentcloud/cdb/v20170320/model/DescribeSupportedPrivilegesResponse.h>
#include <tencentcloud/core/utils/rapidjson/document.h>
#include <tencentcloud/core/utils/rapidjson/writer.h>
#include <tencentcloud/core/utils/rapidjson/stringbuffer.h>

using TencentCloud::CoreInternalOutcome;
using namespace TencentCloud::Cdb::V20170320::Model;
using namespace rapidjson;
using namespace std;

DescribeSupportedPrivilegesResponse::DescribeSupportedPrivilegesResponse() :
    m_globalSupportedPrivilegesHasBeenSet(false),
    m_databaseSupportedPrivilegesHasBeenSet(false),
    m_tableSupportedPrivilegesHasBeenSet(false),
    m_columnSupportedPrivilegesHasBeenSet(false)
{
}

CoreInternalOutcome DescribeSupportedPrivilegesResponse::Deserialize(const string &payload)
{
    Document d;
    d.Parse(payload.c_str());
    if (d.HasParseError() || !d.IsObject())
    {
        return CoreInternalOutcome(Error("response not json format"));
    }
    if (!d.HasMember("Response") || !d["Response"].IsObject())
    {
        return CoreInternalOutcome(Error("response `Response` is null or not object"));
    }
    Value &rsp = d["Response"];
    if (!rsp.HasMember("RequestId") || !rsp["RequestId"].IsString())
    {
        return CoreInternalOutcome(Error("response `Response.RequestId` is null or not string"));
    }
    string requestId(rsp["RequestId"].GetString());
    SetRequestId(requestId);

    if (rsp.HasMember("Error"))
    {
        if (!rsp["Error"].IsObject() ||
            !rsp["Error"].HasMember("Code") || !rsp["Error"]["Code"].IsString() ||
            !rsp["Error"].HasMember("Message") || !rsp["Error"]["Message"].IsString())
        {
            return CoreInternalOutcome(Error("response `Response.Error` format error").SetRequestId(requestId));
        }
        string errorCode(rsp["Error"]["Code"].GetString());
        string errorMsg(rsp["Error"]["Message"].GetString());
        return CoreInternalOutcome(Error(errorCode, errorMsg).SetRequestId(requestId));
    }


    if (rsp.HasMember("GlobalSupportedPrivileges") && !rsp["GlobalSupportedPrivileges"].IsNull())
    {
        if (!rsp["GlobalSupportedPrivileges"].IsArray())
            return CoreInternalOutcome(Error("response `GlobalSupportedPrivileges` is not array type"));

        const Value &tmpValue = rsp["GlobalSupportedPrivileges"];
        for (Value::ConstValueIterator itr = tmpValue.Begin(); itr != tmpValue.End(); ++itr)
        {
            m_globalSupportedPrivileges.push_back((*itr).GetString());
        }
        m_globalSupportedPrivilegesHasBeenSet = true;
    }

    if (rsp.HasMember("DatabaseSupportedPrivileges") && !rsp["DatabaseSupportedPrivileges"].IsNull())
    {
        if (!rsp["DatabaseSupportedPrivileges"].IsArray())
            return CoreInternalOutcome(Error("response `DatabaseSupportedPrivileges` is not array type"));

        const Value &tmpValue = rsp["DatabaseSupportedPrivileges"];
        for (Value::ConstValueIterator itr = tmpValue.Begin(); itr != tmpValue.End(); ++itr)
        {
            m_databaseSupportedPrivileges.push_back((*itr).GetString());
        }
        m_databaseSupportedPrivilegesHasBeenSet = true;
    }

    if (rsp.HasMember("TableSupportedPrivileges") && !rsp["TableSupportedPrivileges"].IsNull())
    {
        if (!rsp["TableSupportedPrivileges"].IsArray())
            return CoreInternalOutcome(Error("response `TableSupportedPrivileges` is not array type"));

        const Value &tmpValue = rsp["TableSupportedPrivileges"];
        for (Value::ConstValueIterator itr = tmpValue.Begin(); itr != tmpValue.End(); ++itr)
        {
            m_tableSupportedPrivileges.push_back((*itr).GetString());
        }
        m_tableSupportedPrivilegesHasBeenSet = true;
    }

    if (rsp.HasMember("ColumnSupportedPrivileges") && !rsp["ColumnSupportedPrivileges"].IsNull())
    {
        if (!rsp["ColumnSupportedPrivileges"].IsArray())
            return CoreInternalOutcome(Error("response `ColumnSupportedPrivileges` is not array type"));

        const Value &tmpValue = rsp["ColumnSupportedPrivileges"];
        for (Value::ConstValueIterator itr = tmpValue.Begin(); itr != tmpValue.End(); ++itr)
        {
            m_columnSupportedPrivileges.push_back((*itr).GetString());
        }
        m_columnSupportedPrivilegesHasBeenSet = true;
    }


    return CoreInternalOutcome(true);
}


vector<string> DescribeSupportedPrivilegesResponse::GetGlobalSupportedPrivileges() const
{
    return m_globalSupportedPrivileges;
}

bool DescribeSupportedPrivilegesResponse::GlobalSupportedPrivilegesHasBeenSet() const
{
    return m_globalSupportedPrivilegesHasBeenSet;
}

vector<string> DescribeSupportedPrivilegesResponse::GetDatabaseSupportedPrivileges() const
{
    return m_databaseSupportedPrivileges;
}

bool DescribeSupportedPrivilegesResponse::DatabaseSupportedPrivilegesHasBeenSet() const
{
    return m_databaseSupportedPrivilegesHasBeenSet;
}

vector<string> DescribeSupportedPrivilegesResponse::GetTableSupportedPrivileges() const
{
    return m_tableSupportedPrivileges;
}

bool DescribeSupportedPrivilegesResponse::TableSupportedPrivilegesHasBeenSet() const
{
    return m_tableSupportedPrivilegesHasBeenSet;
}

vector<string> DescribeSupportedPrivilegesResponse::GetColumnSupportedPrivileges() const
{
    return m_columnSupportedPrivileges;
}

bool DescribeSupportedPrivilegesResponse::ColumnSupportedPrivilegesHasBeenSet() const
{
    return m_columnSupportedPrivilegesHasBeenSet;
}


